@include('backstage/public/_header')
    <!--結果頁快捷搜索框 開始-->
    <div class="search_wrap">
        <form action="index" method="get">
            <table class="search_tab">
                <tr>
                    <th width="120">選擇分類:</th>
                    <td>
                        <select onchange="javascript:location.href='index?type_id='+this.value;" name="type_id" style="font-family: sans-serif;">
                            <option value="0" @if (isset($_GET['type_id']) && $_GET['type_id']==0) selected=selected @endif>全部</option>
                            @foreach ($cate as $v)
                                @if($v->pid==0)
                                    <option value="{{$v->id}}" @if (isset($_GET['type_id']) && $v->id==$_GET['type_id']) selected=selected @endif>{{$v->type_name}}</option>
                                @endif
                                @foreach ($cate as $vv)
                                    @if($vv->pid==$v->id)
                                        <option value="{{$vv->id}}" @if (isset($_GET['type_id']) && $vv->id==$_GET['type_id']) selected=selected @endif>-->{!!preg_replace('/^(&nbsp;|＼s)*|(&nbsp;|＼s)*$/', '', $vv->type_name)!!}</option>
                                    @endif
                                @endforeach
                            @endforeach
                        </select>
                    </td>
                    <th width="70">關鍵字:</th>
                    <td><input type="text" name="keywords" placeholder="關鍵字", value="@if(isset($_GET['keywords'])){{$_GET['keywords']}}@endif"></td>
                    <td><input type="submit" name="sub" value="查詢"></td>
                </tr>
            </table>
        </form>
    </div>
    <!--結果頁快捷搜索框 結束-->

    <!--搜索結果頁面 列表 開始-->
    <div class="result_wrap">
        <!--快捷導航 開始-->
        <div class="result_content">
            <div class="short_wrap">
                <a href="add"><i class="fa fa-plus"></i>新增文章</a>
                <a href="javascript:void(0);" onclick="del();" ><i class="fa fa-recycle"></i>批量刪除</a>
                <a href="javascript:void(0);" onclick="window.location.reload();"><i class="fa fa-refresh"></i>更新排序</a>
            </div>
        </div>
        <!--快捷導航 結束-->
    </div>

    <div class="result_wrap">
        <div class="result_content">
            <table class="list_tab">
                <tr>
                    <th class="tc" width="5%"><input type="checkbox" id="checkAll" value="0"></th>
                    <th class="tc">排序</th>
                    <th class="tc">ID</th>
                    <th>標題</th>
                    <th>所屬欄目</th>
                    <th>點擊</th>
                    <th>發布人</th>
                    <th>狀態</th>
                    <th>更新時間</th>
                    <th>操作</th>
                </tr>
                @foreach ($list as $vb)
                    <tr id="list_{{$vb->id}}">
                        <td class="tc"><input type="checkbox" name="checkbox" value="{{$vb->id}}"></td>
                        <td class="tc">
                            <input type="text" onkeyup="value=value.replace(/[^\d{1,}\-\d{1,}|\d{1,}]/g,'')" onblur="sort('sort',{{$vb->id}})" maxlength="3" value="{{$vb->sort_order}}" sort="{{$vb->sort_order}}" id="sort_{{$vb->id}}">
                        </td>
                        <td class="tc">{{$vb->id}}</td>
                        <td>
                            <a href="javascript:void(0);" onclick="openRim('{{$vb->id}}');">{{$vb->title}}</a>
                        </td>
                        <td>{{$vb->type_name}}</td>
                        <td>{{$vb->art_click}}</td>
                        <td>{{$vb->art_writer or '匿名'}}</td>
                        <td>@if($vb->is_hidden==1) 隱藏 @else 顯示 @endif</td>
                        <td>@if($vb->art_time!=0) {{date('Y-m-d H:i:s',$vb->art_time)}} @endif</td>
                        <td>
                            <a href="edit/{{$vb->id}}">修改</a>
                            <a href="javascript:void(0);" onclick="del({{$vb->id}});">刪除</a>
                        </td>
                    </tr>
                @endforeach
            </table>
        </div>
        <div class="page_nav">
            {{ $list->links('vendor/pagination/default', ['foo' => 'bar']) }}
        </div>
    </div>
    <!--搜索結果頁面 列表 結束-->
    <script type="text/javascript">
        function sort(name,id){
            var olddata = $('#'+name+'_'+id).attr('sort');
            var getdata = $('#'+name+'_'+id).val();
            if(olddata != getdata ){
                $.post("{{$update_sort}}", { 'id': id,'sort': $('#'+name+'_'+id).val(),"_token":"{{csrf_token()}}"},
                function (data){
                    // console.log(data);
                    if(data.status==1){
                        $('#'+name+'_'+id).attr('sort',getdata);
                    }
                    if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }
                    if(data.status==0){
                        layer.msg(data.message, {icon: 2});
                        // window.location.reload(); 
                        $('#'+name+'_'+id).val(olddata);
                    }
                }, "json");
            }
        }
        function getChecked() {
            var gids = new Array();
            $.each($('input:checked'), function(i, n){
                if($(n).val()!=0) gids.push( $(n).val() );
            });
            return gids;
        }
        //刪除
        function del(aid){
            aid = aid ? aid : getChecked();
            // console.log(aid);
            //詢問框
            layer.confirm('刪除後不可恢復，確定要刪除嗎？', {
              btn: ['確定','取消'] //按鈕
            }, function(){
                aid = aid.toString();
                // console.log(aid);
                if(aid == '') return layer.msg('未選中任何數據', {icon: 2,anim: 6});
                // layer.msg('正在刪除...', {icon: 16,shade: 0.01});
                $.post("{{$dodel}}", { 'idstr':aid,"_token":"{{ csrf_token() }}"},
                function (data){
                    if(data.status==1){
                        layer.msg('正在刪除...', {icon: 16,shade: 0.01});
                        setTimeout(function(){
                            aid = aid.split(',');
                            $.each(aid, function(i,n){
                                $('#list_'+n).remove();
                            });
                            layer.msg(data.message, {icon: 1});
                        },2000);
                    }else if(data.status==0){
                        layer.msg(data.message, {icon: 2});
                    }else if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }else if(data.status==2){
                        layer.msg(data.message, {icon: 7});
                    }else{
                        layer.msg('未知原因，刪除失敗', {icon: 2});
                    }
                }, "json");
            }, function(){
              // layer.msg('未做任何操作', {
              //   time: 20000, //20s後自動關閉
              //   btn: ['明白了', '知道了']
                // layer.msg('未做任何操作', {icon: 2});
            });
            
        }
        // 打開查看內容
        function openRim(id){
            layer.open({
              type: 2,
              title:'文章內容',
              skin: 'layui-layer-rim', //加上邊框
              area: ['1000px', '500px'], //寬高
              content: '/backstage/article/show/'+id
            });
        }
    </script>
@include('backstage/public/_footer')